package com.example.designpatterns.behavioral.strategy.entity;

import com.example.designpatterns.behavioral.strategy.commons.MsgResult;
import com.example.designpatterns.behavioral.strategy.commons.Payment;
import com.example.designpatterns.behavioral.strategy.factory.PayStrategy;
import com.example.designpatterns.behavioral.strategy.core.AbstractPayment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * 模拟订单
 *
 * @author scott
 */
@Slf4j
@AllArgsConstructor
@Data
public class Order {

    private String uid;
    private String orderId;
    private double amount;

    public MsgResult pay() {
        return pay(PayStrategy.DEFAULT_PAY);
    }

    public MsgResult pay(Payment payKey) {
        AbstractPayment payment = PayStrategy.get(payKey);
        log.info("欢迎使用{}支付", payment.getName());
        log.info("本次交易金额为:{}，开始扣款", amount);
        return payment.pay(uid, amount);
    }

}
